package CreatingJavaCode;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class CreateHyperlinks
{

  /**
 * @author wed
 * This executable creates all the # links for CTA. At this point of time also some normal links for the games are created. Also some normal links for the tours have to be created.
 * The tours need a description tag first 
 *  Please note to change the correct worksheet for creating links
 * Actual worksheet is 1 for passes cycled 1500
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
    	Workbook workbook = Workbook.getWorkbook(new File("C:\\XLS\\CTA.xls"));
    	Sheet sheet = workbook.getSheet(13);
    	Cell[] count = sheet.getColumn(35);
    	FileWriter fstream = new FileWriter("C:\\XLS\\hyperlinks.txt");
    	BufferedWriter textFile = new BufferedWriter(fstream);
       	for (int i = 1; i < count.length; i++) {
	        Cell hyperlinkENCell = sheet.getCell(35,i);
	        Cell passNameCell = sheet.getCell(4, i);
	        String linkEN = hyperlinkENCell.getContents();
	        String passNameEN = passNameCell.getContents();
	        System.out.println(linkEN);
	        String strippedLink = linkEN.replaceAll("-", "");
	        String completeLink = ("Hyperlink " + strippedLink + " = new Hyperlink(\"Cycling " + passNameEN +"\", \"" + linkEN + "\");" + "\n");
	        String completeLinkTour = completeLink.replaceAll("Cycling", "(3D Tour of").replaceAll("\"[)];", "-tour\");").replaceAll(" = ", "Tour = ");
	        String completeLinkVideo = completeLink.replaceAll("Cycling", "(Video of").replaceAll("\"[)];", "-video\");").replaceAll(" = ", "Video = ");
	        String completeLinkSlideshow = completeLink.replaceAll("Cycling", "(Slideshow of").replaceAll("\"[)];", "-slideshow\");").replaceAll(" = ", "Slideshow = ");
	        String completeLinkConversation = completeLink.replaceAll("Cycling", "(Conversation of").replaceAll("\"[)];", "-conversation\");").replaceAll(" = ", "Conversation = ");
	        String completeLinkGame = completeLink.replaceAll("Cycling", "(Game for").replaceAll("\"[)];", "-game\");").replaceAll(" = ", "Game = ");
	        String completeLinkProfile = completeLink.replaceAll("Cycling", "(Profile for").replaceAll("\"[)];", "-profile\");").replaceAll(" = ", "Profile = ");
	        textFile.write(completeLink);
	        textFile.write(completeLinkTour);
	        textFile.write(completeLinkVideo);
	        textFile.write(completeLinkSlideshow);
	        textFile.write(completeLinkConversation);
	        textFile.write(completeLinkGame);
	        textFile.write(completeLinkProfile);
       	}
       	for (int j = 1; j < count.length; j++) {
	        Cell hyperlinkDECell = sheet.getCell(36,j);
	        Cell passNameDECell = sheet.getCell(5, j);
	        String linkDE = hyperlinkDECell.getContents();
	        String passNameDE = passNameDECell.getContents();
	        String strippedLink = linkDE.replaceAll("-", "");
	        System.out.println(linkDE);
	        String completeLink = ("Hyperlink " + strippedLink + "DE = new Hyperlink(\"Radfahren " + passNameDE +"\", \"" + linkDE + "\");" + "\n");
	        String completeLinkTour = completeLink.replaceAll("Radfahren", "(3D Tour von").replaceAll("\"[)];", "-tour\");").replaceAll(" = ", "Tour = ");
	        String completeLinkVideo = completeLink.replaceAll("Radfahren", "(Video von").replaceAll("\"[)];", "-video\");").replaceAll(" = ", "Video = ");
	        String completeLinkSlideshow = completeLink.replaceAll("Radfahren", "(Slideshow von").replaceAll("\"[)];", "-slideshow\");").replaceAll(" = ", "Slideshow = ");
	        String completeLinkConversation = completeLink.replaceAll("Radfahren", "(Konversation von").replaceAll("\"[)];", "-konversation\");").replaceAll(" = ", "Konversation = ");
	        String completeLinkGame = completeLink.replaceAll("Radfahren", "(Spiel von").replaceAll("\"[)];", "-spiel\");").replaceAll(" = ", "Spiel = ");
	        String completeLinkProfile = completeLink.replaceAll("Radfahren", "(Profil von").replaceAll("\"[)];", "-profil\");").replaceAll(" = ", "Profil = ");
	        textFile.write(completeLink);
	        textFile.write(completeLinkTour);
	        textFile.write(completeLinkVideo);
	        textFile.write(completeLinkSlideshow);
	        textFile.write(completeLinkConversation);
	        textFile.write(completeLinkGame);
	        textFile.write(completeLinkProfile);
       	}
       	for (int k = 1; k < count.length; k++) {
	        Cell hyperlinkNLCell = sheet.getCell(37,k);
	        Cell passNameNLCell = sheet.getCell(6, k);
	        String linkNL = hyperlinkNLCell.getContents();
	        String passNameNL = passNameNLCell.getContents();
	        String strippedLink = linkNL.replaceAll("-", "");
	        System.out.println(linkNL);
	        String completeLink = ("Hyperlink " + strippedLink + "NL = new Hyperlink(\"Fietsen " + passNameNL +"\", \"" + linkNL + "\");" + "\n");
	        String completeLinkTour = completeLink.replaceAll("Fietsen", "(3D Tour van").replaceAll("\"[)];", "-tour\");").replaceAll(" = ", "Tour = ");
	        String completeLinkVideo = completeLink.replaceAll("Fietsen", "(Video van").replaceAll("\"[)];", "-video\");").replaceAll(" = ", "Video = ");
	        String completeLinkSlideshow = completeLink.replaceAll("Fietsen", "(Slideshow van").replaceAll("\"[)];", "-slideshow\");").replaceAll(" = ", "Slideshow = ");
	        String completeLinkConversation = completeLink.replaceAll("Fietsen", "(Conversatie van").replaceAll("\"[)];", "-conversatie\");").replaceAll(" = ", "conversatie = ");
	        String completeLinkGame = completeLink.replaceAll("Fietsen", "(Spel van").replaceAll("\"[)];", "-spel\");").replaceAll(" = ", "spel = ");
	        String completeLinkProfile = completeLink.replaceAll("Fietsen", "(Profiel van").replaceAll("\"[)];", "-profiel\");").replaceAll(" = ", "Profiel = ");
	        textFile.write(completeLink);
	        textFile.write(completeLinkTour);
	        textFile.write(completeLinkVideo);
	        textFile.write(completeLinkSlideshow);
	        textFile.write(completeLinkConversation);
	        textFile.write(completeLinkGame);
	        textFile.write(completeLinkProfile);
       	}
       	for (int l = 1; l < count.length; l++) {
	        Cell hyperlinkITCell = sheet.getCell(38,l);
	        Cell passNameITCell = sheet.getCell(7, l);
	        String linkIT = hyperlinkITCell.getContents();
	        String passNameIT = passNameITCell.getContents();
	        String strippedLink = linkIT.replaceAll("-", "");
	        System.out.println(linkIT);
	        String completeLink = ("Hyperlink " + strippedLink + "IT = new Hyperlink(\"Ciclismo " + passNameIT +"\", \"" + linkIT + "\");" + "\n");
	        String completeLinkTour = completeLink.replaceAll("Ciclismo", "(3D Tour di").replaceAll("\"[)];", "-tour\");").replaceAll(" = ", "Tour = ");
	        String completeLinkVideo = completeLink.replaceAll("Ciclismo", "(Video di").replaceAll("\"[)];", "-video\");").replaceAll(" = ", "Video = ");
	        String completeLinkSlideshow = completeLink.replaceAll("Ciclismo", "(Slideshow di").replaceAll("\"[)];", "-slideshow\");").replaceAll(" = ", "Slideshow = ");
	        String completeLinkConversation = completeLink.replaceAll("Ciclismo", "(Conversazione di").replaceAll("\"[)];", "-conversazione\");").replaceAll(" = ", "Conversazione = ");
	        String completeLinkGame = completeLink.replaceAll("Ciclismo", "(Ascolta di").replaceAll("\"[)];", "-ascolta\");").replaceAll(" = ", "Ascolta = ");
	        String completeLinkProfile = completeLink.replaceAll("Ciclismo", "(Profilo di").replaceAll("\"[)];", "-profilo\");").replaceAll(" = ", "Profilo = ");
	        textFile.write(completeLink);
	        textFile.write(completeLinkTour);
	        textFile.write(completeLinkVideo);
	        textFile.write(completeLinkSlideshow);
	        textFile.write(completeLinkConversation);
	        textFile.write(completeLinkGame);
	        textFile.write(completeLinkProfile);
       	}
       	for (int m = 1; m < count.length; m++) {
	        Cell hyperlinkFRCell = sheet.getCell(39,m);
	        Cell passNameFRCell = sheet.getCell(8, m);
	        String linkFR = hyperlinkFRCell.getContents();
	        String passNameFR = passNameFRCell.getContents();
	        String strippedLink = linkFR.replaceAll("-", "");
	        System.out.println(linkFR);
	        String completeLink = ("Hyperlink " + strippedLink + "FR = new Hyperlink(\"Cyclisme " + passNameFR +"\", \"" + linkFR + "\");" + "\n");
	        String completeLinkTour = completeLink.replaceAll("Cyclisme", "(3D Tour des").replaceAll("\"[)];", "-tour\");").replaceAll(" = ", "Tour = ");
	        String completeLinkVideo = completeLink.replaceAll("Cyclisme", "(Video des").replaceAll("\"[)];", "-video\");").replaceAll(" = ", "Video = ");
	        String completeLinkSlideshow = completeLink.replaceAll("Cyclisme", "(Slideshow des").replaceAll("\"[)];", "-slideshow\");").replaceAll(" = ", "Slideshow = ");
	        String completeLinkConversation = completeLink.replaceAll("Cyclisme", "(Conversation des").replaceAll("\"[)];", "-conversation\");").replaceAll(" = ", "Conversation = ");
	        String completeLinkGame = completeLink.replaceAll("Cyclisme", "(Jouer des").replaceAll("\"[)];", "-jouer\");").replaceAll(" = ", "Jouer = ");
	        String completeLinkProfile = completeLink.replaceAll("Cyclisme", "(Profil des").replaceAll("\"[)];", "-profil\");").replaceAll(" = ", "Profil = ");
	        textFile.write(completeLink);
	        textFile.write(completeLinkTour);
	        textFile.write(completeLinkVideo);
	        textFile.write(completeLinkSlideshow);
	        textFile.write(completeLinkConversation);
	        textFile.write(completeLinkGame);
	        textFile.write(completeLinkProfile);
       	}


    	textFile.close();
    } catch (BiffException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
